<template>
  <el-dialog v-model="visible" :title="dialogDatas.title" @closed="onReset" destroy-on-close>
    <el-form :model="dialogDatas" label-width="105px" ref="formRef">
      <el-form-item label="套餐名称" class="is-required" prop="dialogDatas.datas.mealName">
        <el-input v-model="dialogDatas.datas.mealName" :disabled="isDisabled" clearable />
      </el-form-item>
      <el-form-item label="使用点数" class="is-required" prop="dialogDatas.points">
        <el-input v-model="dialogDatas.datas.points" :disabled="isDisabled" clearable />
      </el-form-item>
      <el-form-item label="套餐描述" class="is-required" prop="dialogDatas.remark">
        <el-input v-model="dialogDatas.datas.remark" type="textarea" :disabled="isDisabled" />
      </el-form-item>
    </el-form>
    <P class="w-full text-center mb6 mt2">包含检测项</P>
    <el-table ref="multipleTableRef" :data="dialogDatas.datas.tableData" style="width: 100%" border>
      <el-table-column type="selection" width="55" v-if="!isDisabled" />
      <el-table-column property="sort" label="sort" />
      <el-table-column property="ID" label="ID" />
      <el-table-column property="reportId" label="Report ID" show-overflow-tooltip />
      <el-table-column property="type" label="Type" />
      <el-table-column property="title" label="Title" />
    </el-table>
    <template #footer v-if="dialogDatas.type !== 'check'">
      <span class="dialog-footer flex justify-center mb4">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="visible = false">确认</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
interface User {
  sort: string;
  ID: string;
  reportId: string;
  type: string;
  title: string;
}
import { ref, reactive, nextTick, watchEffect, computed } from 'vue';
import type { FormInstance } from 'element-plus';
const visible = ref(false);
const formRef = ref<FormInstance>();
let dialogDatas = ref({});
// const form = ref({
//   // mealName: '',
//   // points: '',
//   // remark: ''
// });
const isDisabled = computed(() => (dialogDatas.value.type === 'check' ? true : false));
const tableData = [
  {
    sort: '2016-05-03',
    ID: 'Tom',
    reportId: 'No. 189, Grove St, Los Angeles',
    type: '222',
    title: '4444'
  },
  {
    sort: '2016-05-03',
    ID: 'Tom',
    reportId: 'No. 189, Grove St, Los Angeles',
    type: '222',
    title: '4444'
  },
  {
    sort: '2016-05-03',
    ID: 'Tom',
    reportId: 'No. 189, Grove St, Los Angeles',
    type: '222',
    title: '4444'
  },
  {
    sort: '2016-05-03',
    ID: 'Tom',
    reportId: 'No. 189, Grove St, Los Angeles',
    type: '222',
    title: '4444'
  },
  {
    sort: '2016-05-03',
    ID: 'Tom',
    reportId: 'No. 189, Grove St, Los Angeles',
    type: '222',
    title: '4444'
  },
  {
    sort: '2016-05-03',
    ID: 'Tom',
    reportId: 'No. 189, Grove St, Los Angeles',
    type: '222',
    title: '4444'
  }
];
const init = (data: any) => {
  visible.value = true;
  if (data) dialogDatas.value = JSON.parse(JSON.stringify(data));
};
const onReset = () => {
  if (!formRef.value) return;
  formRef.value.resetFields();
};

defineExpose({ init });
</script>

<style lang="scss" scoped></style>
